﻿/************************************************************************************
 * 
 * 
 * 
 * 
 * 
 * 
 * *********************************************************************************/
using System;

namespace DesignPattern {

    /// <summary>
    /// 
    /// </summary>
    public interface IBuilder {
        /// <summary>
        /// build part a
        /// </summary>
        void BuildPartA();

        /// <summary>
        /// build part b
        /// </summary>
        void BuildPartB();

        /// <summary>
        /// get the builder created product
        /// </summary>
        /// <returns></returns>
        IProduct GetProduct();
    }

    /// <summary>
    /// product interface, has nothing
    /// </summary>
    public interface IProduct {

    }

    /// <summary>
    /// In charge of construct product
    /// </summary>
    public class Director {
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="builder">builder</param>
        public Director(IBuilder builder) {
            builder.BuildPartA();
            builder.BuildPartB();
        }
    }

    /// <summary>
    /// a builder for car, inherit IBuilder interface
    /// </summary>
    public class CarBuilder : IBuilder {
        /// <summary>
        /// build part a
        /// </summary>
        public void BuildPartA() {
            System.Console.WriteLine("Car: Create part a");
        }

        /// <summary>
        /// build part b
        /// </summary>
        public void BuildPartB() {
            System.Console.WriteLine("Car: Create part b");
        }

        /// <summary>
        /// get the product which created by builder
        /// </summary>
        /// <returns></returns>
        public IProduct GetProduct() {
            System.Console.WriteLine("Car: Get a product");

            return null;
        }
    }

    /// <summary>
    /// the process to show builder how to work
    /// </summary>
    public class Processor {
        public void Run() {
            IBuilder builder = new CarBuilder();
            Director director = new Director(builder);

            IProduct product = builder.GetProduct();
        }
    }
}
